package com.example.administrator.yunniuusedcar.holder;

import android.content.Context;
import android.content.Intent;
import android.opengl.Visibility;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.administrator.common.ui.BaseAdapterRV;
import com.example.administrator.common.ui.BaseHolderRV;
import com.example.administrator.yunniuusedcar.MainActivity;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.activity.CommodityDetailsActivity;
import com.example.administrator.yunniuusedcar.model.mode_benn.Home;
import com.example.administrator.yunniuusedcar.model.mode_benn.HomeRanCarListBean;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**  随机汽车
 * Created by USER2015 on 2017/12/17.
 */

public class HomeRanCarHolder extends BaseHolderRV<HomeRanCarListBean.Data> {

    private final List<HomeRanCarListBean.Data> listData;
    private RelativeLayout relativeLayout;
    private ProgressBar progressBar;
    private TextView tvUpdate;
    private ImageView ivHomeCarPage;
    private TextView tvHomeCatInfo;
    private TextView tvHomeCarPay;
    private TextView tvHomeCatPayNum;
    private TextView itemHomeCarSCsave;
    private TextView itemHomeCarSCNum;
    private TextView tvHomeCarMoney;
    private Home.Dataruncars hd;
    private TextView tvHomeYhMoney;

    /**
     * 构造方法
     *  @param context 上下文对象
     * @param parent  指RecyclerView控件
     * @param adapter 适配器
     * @param listData
     */
    public HomeRanCarHolder(Context context, ViewGroup parent,
                            BaseAdapterRV<HomeRanCarListBean.Data> adapter, List<HomeRanCarListBean.Data> listData) {    ///////////---------------
        super(context, parent, adapter, R.layout.item_home_fool); // 内容
        this.listData=listData;    ///////////////////////////////////////--------------------------------.
    }

    @Override
    public void onFindViews(View itemView) {
        itFindByID(itemView);
    }

    @Override
    protected void onRefreshView(HomeRanCarListBean.Data bean, int position) {  // 绑
        Picasso.with(context).load(bean.logo).placeholder(R.drawable.jiazai)
                .into(ivHomeCarPage);      ///   hd : bean ??  汽车图片
        tvHomeCatInfo.setText(bean.name);    // 汽车名称
        tvHomeCarMoney.setText("市场价:￥" + bean.market_price+"万");    //市场价
        //后台待给 付款/销售量
        tvHomeYhMoney.setText("￥" + bean.integral_price +"万");
        itemHomeCarSCsave.setText("收藏 " + bean.collect);     // 收藏数量

        if (relativeLayout .equals(0) ) {    /////////////////////////////?????
            relativeLayout.setVisibility(View.VISIBLE);
        }else {
            relativeLayout.setVisibility(View.GONE);
        }
    }

    private void itFindByID(View itemView) {   // 找
        relativeLayout = (RelativeLayout) itemView.findViewById(R.id.relativeLayout);
//        progressBar = (ProgressBar) itemView.findViewById(R.id.progressBar);       // 进度条
//        tvUpdate = (TextView) itemView.findViewById(R.id.tv_update);    //换一批

        ivHomeCarPage = (ImageView) itemView.findViewById(R.id.iv_home_carPage1);  // 付款....
        tvHomeCatInfo = (TextView) itemView.findViewById(R.id.tv_home_catInfo1);   // 车名 y
        itemHomeCarSCsave = (TextView) itemView.findViewById(R.id.item_home_carSCsave1);  // 收藏
        tvHomeCarMoney = (TextView) itemView.findViewById(R.id.tv_home_carMoney1);  // 市场价   y
        tvHomeYhMoney = (TextView) itemView.findViewById(R.id.tv_home_YhMoney1);    // 优惠价   y

//        tvHomeCarPay = (TextView) itemView.findViewById(R.id.tv_home_carPay1);   // 付 款  (后台未给)

  //      tvHomeCatPayNum = (TextView) itemView.findViewById(R.id.tv_home_catPayNum1);  //付款数量
 //       itemHomeCarSCNum = (TextView) itemView.findViewById(R.id.item _home_carSCNum1);    // 收藏数据 y

//        if ((visi > 0) && (firstVisibleItem == 0)) {
//            if (view.getChildAt(0).getTop() >= 0) {
//                isFirstRow = true;
//            }
//        }

            }

//        ArrayList<HomeRanCarListBean> arrayList = new ArrayList<>();    "car_id":24
    @Override
    protected void onItemClick(View itemView, int position, HomeRanCarListBean.Data bean) {
        super.onItemClick(itemView, position, bean);

        listData.get(position);
       int RanCarID =  bean.car_id;


        
        Intent intent1 = new Intent(MainActivity.mactivity, CommodityDetailsActivity.class);   // 商品详情
//        Intent intent1 = new Intent(context, CommodityDetailsActivity.class);   // 商品详情
        // 获取
        intent1.putExtra("RanCarid",String.valueOf(RanCarID));
        intent1.putExtra("goods_id",bean.car_id);
//        intent1.putExtra("goods_name",position);
//        intent1.putExtra("img",bean.logo);
//        intent1.putExtra("carName",bean.name);
//        intent1.putExtra("HuiYuanJ",bean.integral_price);
//        intent1.putExtra("ShiChangJ",bean.market_price);

////       intent.putExtra(itemV,bean);
      MainActivity.mactivity. startActivity(intent1);
    }
}

